<template>
    <div class="app-container">
      <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="批次号" prop="detailBatch">
          <el-input
            v-model="queryParams.detailBatch"
            placeholder="请输入批次号"
            clearable
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="药品名称" prop="drugName">
          <el-input
            v-model="queryParams.drugName"
            placeholder="请输入药品名称"
            clearable
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
          <el-button icon="Refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
  
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="Download"
            @click="handleExport"
            v-hasPermi="['medicine:detail:export']"
          >导出</el-button>
        </el-col>
        <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>
  
      <el-table v-loading="loading" :data="detailList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="详情ID" align="center" prop="detailId" />
        <el-table-column label="药品名称" align="center" prop="hisMedicineDrug.drugName" />
        <el-table-column label="数量" align="center" prop="detailNum" />
        <el-table-column label="订单ID" align="center" prop="orderId" />
        <el-table-column label="创建时间" align="center" prop="createTime" width="180">
          <template #default="scope">
            <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="备注" align="center" prop="remark" />
        <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template #default="scope">
            <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['medicine:detail:edit']">修改</el-button>
          </template>
        </el-table-column> -->
      </el-table>
      
      <pagination
        v-show="total>0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
      />
  
    </div>
  </template>
  
  <script setup name="Detail">
  import { listDetail, getDetail, delDetail, addDetail, updateDetail } from "@/api/his/detail";
  
  const { proxy } = getCurrentInstance();
  
  const detailList = ref([]);
  const open = ref(false);
  const loading = ref(true);
  const showSearch = ref(true);
  const ids = ref([]);
  const single = ref(true);
  const multiple = ref(true);
  const total = ref(0);
  const title = ref("");
  const route = useRoute();

  const orderId=route.params.orderId;
  
  const data = reactive({
    form: {},
    queryParams: {
      pageNum: 1,
      pageSize: 10,
      orderId,
      detailBatch: null,
    },
    rules: {
      detailNum: [
        { required: true, message: "数量不能为空", trigger: "blur" }
      ],
      detailMoney: [
        { required: true, message: "药品单价不能为空", trigger: "blur" }
      ],
    }
  });
  
  const { queryParams, form, rules } = toRefs(data);
  
  /** 查询订单详情信息列表 */
  function getList() {
    loading.value = true;
    // queryParams.value.orderId = orderId;
    listDetail(queryParams.value).then(response => {
      detailList.value = response.rows;
      total.value = response.total;
      loading.value = false;
    });
  }
  
  // 取消按钮
  function cancel() {
    open.value = false;
    reset();
  }
  
  
  
  /** 搜索按钮操作 */
  function handleQuery() {
    queryParams.value.pageNum = 1;
    getList();
  }
  
  /** 重置按钮操作 */
  function resetQuery() {
    proxy.resetForm("queryRef");
    handleQuery();
  }
  /** 导出按钮操作 */
  function handleExport() {
    proxy.download('medicine/detail/export', {
      ...queryParams.value
    }, `detail_${new Date().getTime()}.xlsx`)
  }
  
  getList();
  </script>
  